package com.th.apicenter.oppo;

import com.th.apicenter.oppo.entity.ThOppoData;
import com.th.apicenter.oppo.service.OPPOService;
import com.th.apicenter.tools.ThResult;
import com.th.apicenter.tools.ThTools;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/oppo")
@Slf4j
public class OPPOController {


    @Autowired
    private OPPOService oppoService;

    /**
     * oppo的检测连接
     * http://apibiz.tinghongzz.com/oppo/monitor?account_id=1000464930&os=$os$&os_version=$ov$&model=$m$&lang=$lan$&country=$c$&width=$w$&height=$h$&pkg=$pkg$&app_version=$av$&useragent=$ua$&referer=$rf$&ip=__IP__&ts=__TS__&spuid=$spuid$&net_type=$nt$&carrier=$ca$&progress=$progress$&imei=$im$&OAID=__OAID__&ad_id=$ad$&ad_name=$an$&req_id=$req$&owner_id=$ownerid$&plan_id=$planid$&group_id=$groupid$
     *
     * @param os
     * @param os_version
     * @param model
     * @param imei
     * @param OAID
     * @param ad_id
     * @param req_id
     * @param owner_id
     * @param plan_id
     * @param group_id
     * @return
     */
    @GetMapping("/monitor")
    public ThResult receiveUrl(@RequestParam(name = "account_id", required = false) String account_id,
                                @RequestParam(name = "os", required = false) String os,
                                @RequestParam(name = "os_version", required = false) String os_version,
                                @RequestParam(name = "model", required = false) String model,
                                @RequestParam(name = "lang", required = false) String lang,
                                @RequestParam(name = "country", required = false) String country,
                                @RequestParam(name = "width", required = false) String width,
                                @RequestParam(name = "height", required = false) String height,
                                @RequestParam(name = "pkg", required = false) String pkg,
                                @RequestParam(name = "app_version", required = false) String app_version,
                                @RequestParam(name = "useragent", required = false) String useragent,
                                @RequestParam(name = "referer", required = false) String referer,
                                @RequestParam(name = "ip", required = false) String ip,
                                @RequestParam(name = "ts", required = false) String ts,
                                @RequestParam(name = "spuid", required = false) String spuid,
                                @RequestParam(name = "net_type", required = false) String net_type,
                                @RequestParam(name = "carrier", required = false) String carrier,
                                @RequestParam(name = "progress", required = false) String progress,
                                @RequestParam(name = "imei", required = false) String imei,
                                @RequestParam(name = "OAID", required = false) String OAID,
                                @RequestParam(name = "ad_id", required = false) String ad_id,
                                @RequestParam(name = "ad_name", required = false) String ad_name,
                                @RequestParam(name = "req_id", required = false) String req_id,
                                @RequestParam(name = "owner_id", required = false) String owner_id,
                                @RequestParam(name = "plan_id", required = false) String plan_id,
                                @RequestParam(name = "group_id", required = false) String group_id) {
        log.info("account_id:{}", account_id);
        log.info("os:{}", os);
        log.info("os_version:{}", os_version);
        log.info("model:{}", model);
        log.info("imei:{}", imei);
        log.info("OAID:{}", OAID);
        log.info("ad_id:{}", ad_id);
        log.info("req_id:{}", req_id);
        log.info("owner_id:{}", owner_id);
        log.info("plan_id:{}", plan_id);
        log.info("ad_name:{}", ad_name);
        log.info("group_id:{}", group_id);
        log.info("lang:{}", lang);
        log.info("country:{}", country);
        log.info("width:{}", width);
        log.info("height:{}", height);
        log.info("pkg:{}", pkg);
        log.info("app_version:{}", app_version);
        log.info("useragent:{}", useragent);
        log.info("referer:{}", referer);
        log.info("ip:{}", ip);
        log.info("ts:{}", ts);
        log.info("spuid:{}", spuid);
        log.info("net_type:{}", net_type);
        log.info("carrier:{}", carrier);
        log.info("progress:{}", progress);

        ThOppoData thOppoData = new ThOppoData();
        thOppoData.setAccountId(account_id);
        thOppoData.setOs(ThTools.isNull(os) ? "" : os);
        thOppoData.setOsVersion(ThTools.isNull(os_version) ? "" : os_version);
        thOppoData.setModel(ThTools.isNull(model) ? "" : model);
        thOppoData.setLang(ThTools.isNull(lang) ? "" : lang);
        thOppoData.setCountry(ThTools.isNull(country) ? "" : country);
        thOppoData.setWidth(ThTools.isNull(width) ? "" : width);
        thOppoData.setHeight(ThTools.isNull(height) ? "" : height);
        thOppoData.setPkg(ThTools.isNull(pkg) ? "" : pkg);
        thOppoData.setAppVersion(ThTools.isNull(app_version) ? "" : app_version);
        thOppoData.setUseragent(ThTools.isNull(useragent) ? "" : useragent);
        thOppoData.setReferer(ThTools.isNull(referer) ? "" : referer);
        thOppoData.setIp(ThTools.isNull(ip) ? "" : ip);
        thOppoData.setTs(ThTools.isNull(ts) ? "" : ts);
        thOppoData.setSpuid(ThTools.isNull(spuid) ? "" : spuid);
        thOppoData.setNetType(ThTools.isNull(net_type) ? "" : net_type);
        thOppoData.setCarrier(ThTools.isNull(carrier) ? "" : carrier);
        thOppoData.setProgress(ThTools.isNull(progress) ? "" : progress);
        thOppoData.setImei(ThTools.isNull(imei) ? "" : imei);
        thOppoData.setOaid(ThTools.isNull(OAID) ? "" : OAID);
        thOppoData.setAdId(ThTools.isNull(ad_id) ? "" : ad_id);
        thOppoData.setAdName(ThTools.isNull(ad_name) ? "" : ad_name);
        thOppoData.setReqId(ThTools.isNull(req_id) ? "" : req_id);
        thOppoData.setOwnerId(ThTools.isNull(owner_id) ? "" : owner_id);
        thOppoData.setPlanId(ThTools.isNull(plan_id) ? "" : plan_id);
        thOppoData.setGroupId(ThTools.isNull(group_id) ? "" : group_id);

        String receive = oppoService.receive(thOppoData);
        return ThResult.success(receive);
    }

}
